<template>
  <a-modal
    :title="title"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭"
    wrapClassName="ant-modal-cust-warp"
    style="top:5%;overflow-y: hidden"
    :width="1200"
  >
    <a-table
      size="small"
      bordered
      rowKey="id"
      :columns="columns"
      :dataSource="data"
      :pagination="pagination"
      :loading="loading"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type:'radio'}"
    >
      <!-- <span slot="action" slot-scope="text, record">
        <a @click="selectModel(record)">选择</a>
      </span>-->
    </a-table>
  </a-modal>
</template>

<script>
import { getDeployedList } from '@/api/activiti'

export default {
  data() {
    return {
      title: '选择流程定义',
      confirmLoading: false,
      visible: false,
      loading: false,
      pagination: {},
      selectedRowKeys: [],
      data: [],
      columns: [
        {
          title: '名称',
          align: 'center',
          dataIndex: 'name'
        },
        {
          title: '类别',
          align: 'center',
          dataIndex: 'category'
        },
        {
          title: '版本',
          align: 'center',
          dataIndex: 'version'
          // },
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align: 'center',
          //   scopedSlots: { customRender: 'action' }
        }
      ]
    }
  },
  methods: {
    show() {
      this.visible = true
      this.fetchModelList()
    },
    fetchModelList() {
      const vm = this
      this.loading = true
      getDeployedList().then(res => {
        if (res.success) {
          vm.data = res.result.records
          vm.pagination.total = res.result.total
        }
        vm.loading = false
      })
    },
    onSelectChange(keys, selections) {
      this.selectedRowKeys = keys
      this.selectedModel = Object.assign({}, selections[0])
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      this.$emit('selectModel', this.selectedModel)
      this.close()
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>